<template>
  <div class="supplier-details">
    <FixedOperation>
      <el-row>
        <el-col :span="10" :offset="14" class="flex justify-end">
          <slot></slot>
          <el-button type="primary" plain @click="viewProcess" v-if="proInsId">
            查看流程</el-button
          >
          <el-button type="primary" plain @click="handleBack"> 返回</el-button>
        </el-col>
      </el-row>
    </FixedOperation>
    <div class="tatle-box app-container" id="printTest" v-loading="loading">
      <div class="text-center">{{ formData.annual }}年度供应商评价表</div>
      <div class="flex justify-between p-y-1">
        <div>
          <dict-drop :options="supplier_type" :value="formData.type" />
        </div>
        <div>
          填表日期:{{ parseTime(formData.createTime, '{y}年{m}月{d}日') }}
        </div>
      </div>
      <table v-if="formData.type != '3'">
        <tbody>
          <!-- 基本信息 -->
          <tr>
            <td colspan="4" class="w-42px text-center" style="padding: 1rem">
              基本信息
            </td>
          </tr>
          <tr>
            <td class="text-center">供应商名称</td>
            <td class="text-center">
              {{ formData.supplierName }}
            </td>
            <td class="text-center">供应商地址</td>
            <td class="text-center">
              {{ formData.address }}
            </td>
          </tr>
          <tr>
            <td class="text-center">合作事项</td>
            <td class="text-center">
              {{ formData.cooperationMatters }}
            </td>
            <td class="text-center">供应产品/服务</td>
            <td class="text-center">
              {{ formData.supplierProduct }}
            </td>
          </tr>
          <tr>
            <td class="text-center">联系人</td>
            <td class="text-center">
              {{ formData.contactName }}
            </td>
            <td class="text-center">联系电话</td>
            <td class="text-center">
              {{ formData.contactPhone }}
            </td>
          </tr>
          <tr>
            <td colspan="2" class="text-center">供应商类别</td>
            <td colspan="2" class="text-center">
              <dict-drop
                :options="evaluate_supplier_type"
                :value="formData.supplierType"
              />
            </td>
          </tr>
          <tr>
            <td colspan="2" class="text-center">附件</td>
            <td colspan="2" class="text-center">
              <div
                v-for="item in formData.supplierEvaluateFileList"
                :key="item.fileName"
              >
                <el-link
                  @click="viewFiles(item.url)"
                  :underline="false"
                  type="primary"
                  >{{ item.origFileName }}</el-link
                >
              </div>
            </td>
          </tr>
        </tbody>
      </table>
      <table v-if="formData.type != '3'">
        <tbody>
          <tr>
            <td class="text-center" colspan="4" style="border-top: 0">
              年度评价内容（可根据实际合作情况调整）
            </td>
          </tr>
          <tr>
            <td class="text-center">评价指标</td>
            <td class="text-center">各指标项下具体评价条款解释</td>
            <td class="text-center">参考分值</td>
            <td class="text-center">评价分值</td>
          </tr>
          <!-- 1.经营情况 -->
          <tr>
            <td class="text-center" rowspan="4">1.经营情况</td>
            <td class="text-center">
              -营业合法性：营业执照、代理证书或代理协议等；
            </td>
            <td class="text-center" rowspan="4">10</td>
            <td class="text-center" rowspan="4">{{ formData.manageScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              -经营规模：成立时间、注册资金、组织架构、人员规模及分布、客户群等；
            </td>
          </tr>
          <tr>
            <td class="text-center">
              -专业程度：技术领先，市场占有力强，品牌效应好；
            </td>
          </tr>
          <tr>
            <td class="text-center">-财务状况：财务报表、关键财务指标。</td>
          </tr>
          <!-- 2.质量水平 -->
          <tr>
            <td class="text-center" rowspan="3">2.质量水平</td>
            <td class="text-center">
              -资质认证：ISO9000、环境认证、职业健康安全认证、信息安全（隐私信息）认证、产品可靠性、知识产权证书等，有一套品质保证体系，且按照相关要求执行；
            </td>
            <td class="text-center" rowspan="3">20</td>
            <td class="text-center" rowspan="3">{{ formData.qualityScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              -质量情况：产品检验、生产过程的满意度；产品/服务与本单位的要求以及相关技术指标的匹配程度；
            </td>
          </tr>
          <tr>
            <td class="text-center">-供应渠道：供应商所供产品的来源。</td>
          </tr>
          <!-- 3.合作情况 -->
          <tr>
            <td class="text-center" rowspan="5">3.合作情况</td>
            <td class="text-center">
              -供应周期：按约定准时或提前交付，满足本公司需求变动的能力/重新安排或取消/以及对数量变化的忍受程度；
            </td>
            <td class="text-center" rowspan="5">45</td>
            <td class="text-center" rowspan="5">
              {{ formData.cooperationScore }}
            </td>
          </tr>
          <tr>
            <td class="text-center">
              -采购成本：在同类产品/服务中是否有价格优势；
            </td>
          </tr>
          <tr>
            <td class="text-center">-交易账期：付款比例及账期时长；</td>
          </tr>
          <tr>
            <td class="text-center">-执行情况：执行效率、履约符合度；</td>
          </tr>
          <tr>
            <td class="text-center">
              -合作意愿：是否愿意投入足够的资源（如人员保障、备库存等）来维护和发展合作关系。
            </td>
          </tr>
          <!-- 4.服务配合 -->
          <tr>
            <td class="text-center" rowspan="3">4.服务配合</td>
            <td class="text-center">
              -售前服务：提供相应的技术支持和信息支持；组建专门的服务团队并指定相应的负责人；对突发性或临时性需求的快速响应及相应产品与服务的迅速到位；
            </td>
            <td class="text-center" rowspan="3">15</td>
            <td class="text-center" rowspan="3">{{ formData.serviceScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              -物流服务：交付产品整个过程所能提供的相关物流服务（货物及时发货、货物准确送达、货物完好送达、运输信息及时反馈、客户投诉率及投诉处理时效、回单返回及时率等）；
            </td>
          </tr>
          <tr>
            <td class="text-center">
              -售后服务：解决问题的及时性、相应程度及满意度。
            </td>
          </tr>
          <!-- 5.其他相关要求 -->
          <tr>
            <td class="text-center" rowspan="3">5.其他相关要求</td>
            <td class="text-center">
              -相关时，是否如约履行合同中规定的信息安全保密及隐私信息保密事宜，无信息安全及隐私泄密。
            </td>
            <td class="text-center" rowspan="3">10</td>
            <td class="text-center" rowspan="3">
              {{ formData.otherRequirementsScore }}
            </td>
          </tr>
          <tr>
            <td class="text-center">
              -相关时，所供货品是否满足环保要求及安全要求，是否能够提供相应证据。
              等）；
            </td>
          </tr>
          <tr>
            <td class="text-center">
              -相关时，供应商是否对其环境保护能力及职业健康安全能力进行书面承诺及保证。
            </td>
          </tr>
          <!-- 6.其他加、减分 -->
          <tr>
            <td class="text-center" rowspan="6">6.其他加、减分</td>
            <td class="text-center">（需写明加、减分的事项和原因）</td>
            <td class="text-center">+/-</td>
            <td class="text-center"></td>
          </tr>
          <tr>
            <td class="text-center">
              如内部不良评价情况；{{ formData.badEvaluationReason }}
            </td>
            <td class="text-center">2</td>
            <td class="text-center">{{ formData.badEvaluationScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              如征信预警信息情况（有预警风险减分）：{{
                formData.warningInformationReason
              }}
            </td>
            <td class="text-center">2</td>
            <td class="text-center">{{ formData.warningInformationScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              如客户征信评分（低于590分减分）：{{ formData.creditRatingReason }}
            </td>
            <td class="text-center">2</td>
            <td class="text-center">{{ formData.creditRatingScore }}</td>
          </tr>
          <tr>
            <td class="text-center">
              如良好的合作诚意；{{ formData.cooperationSincerityReason }}
            </td>
            <td class="text-center">2</td>
            <td class="text-center">
              {{ formData.cooperationSincerityScore }}
            </td>
          </tr>
          <tr>
            <td class="text-center">
              作为战略型、重要型供应商的酌情加分；{{
                formData.significantSupplierReason
              }}
            </td>
            <td class="text-center">2</td>
            <td class="text-center">{{ formData.significantSupplierScore }}</td>
          </tr>
          <tr>
            <td class="text-center"></td>
            <td class="text-center"></td>
            <td class="text-center">综合得分：</td>
            <td class="text-center">{{ sumVal }}</td>
          </tr>
        </tbody>
      </table>
      <table v-if="formData.type != '3'">
        <tbody>
          <tr>
            <td class="text-center" colspan="6" style="border-top: 0">
              等级评定标准
            </td>
          </tr>
          <tr>
            <td class="w-4/24 text-center">等级划分</td>
            <td class="w-4/24 text-center">不合格</td>
            <td class="w-4/24 text-center">合格</td>
            <td class="w-4/24 text-center">良好</td>
            <td class="w-4/24 text-center">优秀</td>
            <td class="w-4/24 text-center">等级结果</td>
          </tr>
          <tr>
            <td class="text-center">等级得分要求</td>
            <td class="text-center">≦60</td>
            <td class="text-center">≧60</td>
            <td class="text-center">≧80</td>
            <td class="text-center">≧90</td>
            <td class="text-center">{{ scoreRes }}</td>
          </tr>
        </tbody>
      </table>
      <table v-if="formData.type == '3'">
        <tbody>
          <tr>
            <td>企业名称</td>
            <td>{{ formData.supplierName }}</td>
            <td>企业税号</td>
            <td>{{ formData.supplierTaxcode }}</td>
          </tr>
          <tr>
            <td>地址</td>
            <td>{{ formData.address }}</td>
            <td>联系人</td>
            <td>{{ formData.contactName }}</td>
          </tr>
          <tr>
            <td>电话</td>
            <td>{{ formData.contactPhone }}</td>
            <td>联行号</td>
            <td>{{ formData.interbankNumber }}</td>
          </tr>
          <tr>
            <td>开户银行</td>
            <td>{{ formData.depositBank }}</td>
            <td>银行账号</td>
            <td>{{ formData.bankAccount }}</td>
          </tr>
          <tr>
            <td>支付说明</td>
            <td colspan="3">{{ formData.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>
<script setup name="SupplierDetails">
import { useRouter, useRoute } from 'vue-router'
import { getEvaluate } from '@/api/supplierManage/index'
import { viewFile } from '@/utils/commo'
import useUserStore from '@/store/modules/user'
import useTagsViewStore from '@/store/modules/tagsView'

const userStore = useUserStore()
const router = useRouter()
const route = useRoute()
const { proxy, type } = getCurrentInstance()

const { evaluate_supplier_type, supplier_type } = proxy.useDict(
  'evaluate_supplier_type',
  'supplier_type'
)

const formData = ref({})

const data = reactive({
  loading: false
})
let { loading } = toRefs(data)

const proInsId = ref('')
watchEffect(() => {
  if (route.query.evaluateId) {
    console.log('这是详情！')
    getFormData(route.query.evaluateId)
    // statusForm.value.name = formData.value.name
  }
  if (route.query.proInsId) {
    proInsId.value = route.query.proInsId
  }
})
const scoreVal = ref(0)
const sumVal = computed(() => {
  let sum = 0
  let {
    manageScore,
    qualityScore,
    cooperationScore,
    serviceScore,
    otherRequirementsScore,
    badEvaluationScore,
    warningInformationScore,
    creditRatingScore,
    cooperationSincerityScore,
    significantSupplierScore
  } = formData.value
  sum =
    Number(manageScore) +
    Number(qualityScore) +
    Number(cooperationScore) +
    Number(serviceScore) +
    Number(otherRequirementsScore) +
    Number(badEvaluationScore) +
    Number(warningInformationScore) +
    Number(creditRatingScore) +
    Number(cooperationSincerityScore) +
    Number(significantSupplierScore)
  scoreVal.value = sum
  return sum
})
const scoreRes = computed(() => {
  let res = '结果'
  switch (true) {
    case scoreVal.value >= 90:
      res = '优秀'
      break
    case 80 <= scoreVal.value && scoreVal.value < 90:
      res = '良好'
      break
    case 60 <= scoreVal.value && scoreVal.value < 80:
      res = '合格'
      break

    default:
      res = '不合格'
      break
  }
  return res
})
/** 获取产品详情
 * @param {number}  id 表单id
 */

function getFormData(id) {
  loading.value = true
  getEvaluate(id).then(res => {
    formData.value = res.data
    loading.value = false
    console.log('formData.value', formData.value)
  })
}

// 预览文件
function viewFiles(url) {
  viewFile(url, userStore.userInfo.nickName)
}

function goTo(url, data) {
  router.push({ path: url, query: data })
}
// 初始化
function init() {
  //   getFormData(route.query.productId)
  //   statusForm.value.name = formData.value.name
}
// 查看流程
function viewProcess() {
  router.push({
    path: '/process/workDetail',
    query: {
      procInsId: proInsId.value,
      //   taskId: row.taskId,
      processed: false,
      isCirculation: route.query?.isCirculation || undefined
    }
  })
}
// 返回handleBack
const handleBack = () => {
  useTagsViewStore().delView(router.currentRoute.value)
  router.go(-1)
}
init()
</script>
<style lang="scss" scoped>
.tatle-box {
  padding: 20px;
  table {
    @apply border-collapse w-full;
    td {
      @apply border border-solid border-gray-300 p-2;
      box-sizing: border-box;
    }
  }
}
</style>
